package com.pdool.game.controller;

import com.pdool.api.service.room.IRoomService;
import com.pdool.game.dict.CardConfig;
import com.pdool.game.dict.vo.CardVo;
import com.pdool.game.entity.ApiUserEntity;
import com.pdool.game.service.UserService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentMap;

@RestController
public class TestController {
    @DubboReference(url = "127.0.0.1:9999")
    IRoomService roomService;

    @GetMapping("/test")
    public String test() {
        return roomService.roomCall("game to room ");
    }
    @Resource
    UserService userService;
    @Resource
    CacheManager cacheManager;
    @Resource
    CardConfig cardConfig;


    @GetMapping("test3")
    public void test3(){
        Map<Integer, CardVo> all = cardConfig.getAll();
        List<ApiUserEntity> apiUserEntities = userService.queryUser();
        System.out.println();
    }


    @GetMapping("test2")
    public void test2(){
        ApiUserEntity apiUserEntities = userService.queryUserOne(10000);
        System.out.println();
        //获取cacheMap中所有缓存对象的名称
//        Collection<String> cacheNames = cacheManager.getCacheNames();
//        for (String s : cacheNames) {
//            //遍历所有缓存对象
//            Cache cache = cacheManager.getCache(s);
//            System.out.println(cache.getName());
//            //获取ConcurrentMapCache对象中的store实例对象，以ConcurrentMap形式返回
//            ConcurrentMap<Object, Object> map = (ConcurrentMap<Object, Object>) cache.getNativeCache();
//            Collection<Object> collection = map.values();
//            //遍历缓存对象中的所有元素
//            for (Object o : collection) {
//                System.out.println(o);
//            }
//        }
    }
}
